{% load static %}
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- 引入核心的css文件 -->
    <link href="{% static "layui/css/layui.css" %}" rel="stylesheet" media="all">
    <!-- 引入核心的js文件-->
    <script src="{% static "layui/layui.js" %}"></script>
    <!-- 新 Bootstrap5 核心 CSS 文件 -->
    <link rel="stylesheet" href="{% static "css/bootstrap.min.css" %}" type="text/css">
    <script src="{% static "js/jquery-3.6.0.min.js" %}"></script>

    <!-- 最新的 Bootstrap5 核心 JavaScript 文件 -->
    <script type="text/javascript" src="{% static "js/bootstrap.min.js" %}"></script>

    <title>Document</title>


    <style>
        .layui-form-label {
            width: 150px !important;
            text-align: center !important;
        }

        .layui-input {
            width: 280px;
        }

    </style>
</head>
<body>
<!-- 添加和修改的弹出层开始 -->

<div id="saveOrUpdateDiv">

    <form class="layui-form" action="" lay-filler="dataFrm" id="dataFrm">
        {% csrf_token %}

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">计划任务名称:</label>
                <div class="layui-input-inline">
                    <!-- 隐藏的 input 框   <input type="hidden" > -->
                    <input type="hidden" class="layui-input dsrwid" name="dsrwid">
                    <input type="hidden" class="layui-input id_active_id" name="id_active_id">

                    <input type="text" required="required" autocomplete="off" readonly
                           class="layui-input switch_name" name="switch_name">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">开始时间:</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input switch_start_time " id="switch_start_time"   name="switch_start_time" placeholder="yyyy-MM-dd">
                </div>
            </div>

        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">结束时间:</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input switch_end_time " id="switch_end_time" name="switch_end_time" placeholder="yyyy-MM-dd">
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button"
                        class="layui-btn layui-btn-lg layui-btn-radius layui-btn-normal layui-icon layui-icon-ok"
                        lay-submit="" lay-filter="updateSubmit" >修改
                </button>


            </div>
        </div>
    </form>
</div>

<script type="text/javascript">

    //全局定义一次, 加载formSelects  这玩意好像都没使用到
    layui.config({
        base: "{%static '/js/' %}" //此处路径请自行处理, 可以使用绝对路径
    }).extend({
        formSelects: 'formSelects'
    });

    layui.use(['form', 'layer', 'table', "formSelects", 'laytpl', 'laydate'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            table = layui.table,
            laydate = layui.laydate;
        var formSelects = layui.formSelects;

        //日期时间选择器
        laydate.render({
            elem: '#switch_start_time'

        });

        //日期时间选择器
        laydate.render({
            elem: '#switch_end_time'

        });


        form.on("submit(updateSubmit)", function (data) {
            //弹出loading
            // 实际使用时的提交信息
            var dsrwid = $('.dsrwid').val();
            var id_active_id = $('.id_active_id').val();
            var switch_name = $('.switch_name').val();
            var switch_start_time = $('.switch_start_time').val();
            var switch_end_time = $('.switch_end_time').val();

            var csrf_token = $("input[name='csrfmiddlewaretoken']").val();

            //弹出loading
            var index = layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
            $.ajax({
                url: "/editdsrwjh/",
                // data:$("#dataFrm").serialize(),
                data: {
                    "dsrwid": dsrwid,
                    "switch_name": switch_name,
                    "switch_start_time": switch_start_time,
                    "switch_end_time": switch_end_time,
                    "id_active_id": id_active_id,
                    'csrfmiddlewaretoken': csrf_token,
                },
                type: "post",
                success(res) {
                    if (res.code === 200) {
                        layer.msg("修改操作成功！", {icon: 6});
                    }
                },
                error() {
                    layer.msg("修改操作失败！", {icon: 5});
                }
            });
            setTimeout(function () {
                layer.closeAll(index);
                layer.closeAll("updatesdsrwjh.html");
                //刷新父页面
                parent.location.reload();
            }, 1000);
            return false;
        });
    });
</script>
</body>
</html>
